package com.csdj.t301.cloud.controller;

import com.csdj.t301.cloud.entity.User;
import com.csdj.t301.cloud.mapper.UserMapper;
import com.csdj.t301.cloud.uitls.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * author:cloud
 * date:2021/2/23 0023
 **/
@WebServlet(name="/test")
public class TestServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        SqlSession session = SqlSessionUtil.getSession();
        String uid = req.getParameter("uid");
        UserMapper userMapper = session.getMapper(UserMapper.class);
        User user = userMapper.findById(Integer.valueOf(uid));
        PrintWriter writer = resp.getWriter();
        if(user == null){
            writer.write("no user");
        }else{
            writer.write(user.toString());
        }
        writer.flush();
        session.close();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
